<?php 
    namespace Admin\Controller;


    class QuestionController extends AdminController{
       public function index(){
        if ($_GET['condition']==1) {
        $map = 'report=1';
         
        }elseif ($_GET['condition']==2) {
          $map = 'display=0';
        }else{
          $map = '';
        }
        $d = D('question');
        $p=getpage($d,$map,10);
        $list = $d->field('id,name,topic_name,display,user_name,report,datetime,answer_num')->where($map)->order('id')->select();
        $this->assign('list',$list);
        $page = $p->show();

        // var_dump($list);exit;


        $this->assign('page',$page);
        $this->display('Question/index');
       }


       public function qs_display()
       { 
         // var_dump($_GET);exit;
        changedenied($_GET['id'],'display',$_GET['display'],'question');

       }
        public function report()
       { 
         // echo $_GET['report'];
        changedenied($_GET['id'],'report',$_GET['report'],'question');
        
       }
       public function edit()
       {   
            $id = I('get.id/d');
            $data = D('question')->find($id);
            // var_dump($data);exit;
            // 查询分类表
            $topiclist = D('topics')->field('name')->select();
            // var_dump($topiclist);exit;

            $this->assign('topiclist',$topiclist);
            $this->assign('data',$data);
            $this->display('Question/edit');
       }

       public function save()
       {
           $d = D('question');
           if (!$d->create()) {
                $this->error($d->getError());
           }else{
             if ($d->save() > 0)
             {
                $this->success('编辑成功',U('Question/index'));
             }else{
                $this->error('编辑失败');
             }
           }
       }


    }